var express = require('express');
var router = express.Router();
var favoriteApi = require('../api/favorites')
/* GET home page. */
router.get('/', function (req, res, next) {
    res.render('index', { title: 'Express' });
});
// 用于服务端收藏信息添加
router.post(`/add`, async function (req, res, next) {
    let data =  await favoriteApi.add(req.body);
      res.send(data);
  });


router.get('/list', async function (req, res, next) {
    const newData = await favoriteApi.getAll()
    res.send([newData])
});



router.get('/find/userId=:userId', async function (req, res, next) {
    const { userId } = req.params;
    console.log(userId)
    const data = await favoriteApi.findId(userId);
    console.log(data);
    res.send(data)
});


router.delete('/delete/:_id', async function (req, res, next) {
    const {_id}=req.params;
    console.log(_id);
    await favoriteApi.delete(_id);
    res.send('')
});



module.exports = router;
